package com.Maykk.Demo02;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
 * @ClassName: MapTest
 * @Description: TODO HashMap 集合存储学生类
 * @Author: MaykkStar@163.com
 */
public class MapTest {
    public static void main(String[] args) {
        HashMap<String, Student> hm = new HashMap<>();
        hm.put("001", new Student("Tom", 18));
        hm.put("002", new Student("Lucy", 16));
        hm.put("004", new Student("Miya", 14));
        hm.put("003", new Student("Lily", 19));
        hm.put("005", new Student("City", 20));

        // 遍历方法一
        // Collection<Student> values = hm.values();
        // for(Student stu : values) {
        //     System.out.println(stu.getName() + ", "+stu.getAge());
        // }

        // 遍历方法二
        // Set<String> keySet = hm.keySet();
        // for (String set : keySet) {
        //     System.out.println(set + "<==>" + hm.get(set));
        // }

        // 遍历方法三
        Set<Map.Entry<String, Student>> entries = hm.entrySet();
        for (Map.Entry<String, Student> stu : entries) {
            String key = stu.getKey();
            String name = stu.getValue().getName();
            int age = stu.getValue().getAge();
            System.out.println(key + " <==> " + name + ", " + age);
        }

        // Set<Map.Entry<String, Student>> entries = hm.entrySet();
        // for (Map.Entry<String, Student> stu : entries) {
        //     System.out.println(stu);
        // }
    }
}
